prepare("select product_code from products ORDER BY product_code DESC LIMIT 1") ; $getlast->execute() ; //if($getlast->rowcount() > 0) //{ $lastid = $getlast->fetchColumn() ; $newid = $lastid + 1 ; if(isset($_POST['btnsave'])) { //$username = $_POST['user_name'];// user name //$userjob = $_POST['user_job'];// user email $title = $_POST['title']; $authur = $_POST['authur']; $price = $_POST['price']; $intro = $_POST['descrp']; //$ddst = $_POST['ddescrp']; $cat = $_POST['cat']; $imgFile = $_FILES['user_image']['name']; $tmp_dir = $_FILES['user_image']['tmp_name']; $imgSize = $_FILES['user_image']['size']; //if(empty($userjob)){ //$errMSG = "Please Enter Picture description."; //} //else if(empty($imgFile)){ $errMSG = "Please Select Image File."; } else { $upload_dir = '../img/'; // upload directory $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension // valid image extensions $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions // rename uploading image $userpic = rand(1000,1000000).".".$imgExt; // allow valid image file formats if(in_array($imgExt, $valid_extensions)){ // Check file size '5MB' if($imgSize < 5000000) { move_uploaded_file($tmp_dir,$upload_dir.$userpic); } else{ $errMSG = "Sorry, your file is too large."; } } else{ $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; } } // if no error occured, continue .... if(!isset($errMSG)) { $pd = 'pdf' ; $stmt = $DB_con->prepare('INSERT INTO books(category,title,authur,price,image,intro,pdf_file) VALUES(:ct,:a,:b,:c,:d,:e,:p)'); $stmt->bindParam(':ct',$cat); $stmt->bindParam(':a',$title); $stmt->bindParam(':b',$authur); $stmt->bindParam(':c',$price); $stmt->bindParam(':d',$userpic); $stmt->bindParam(':e',$intro); $stmt->bindParam(':p',$pd); if($stmt->execute()) { $last_id = $DB_con->lastInsertId(); $_SESSION['id'] = $last_id ; $successMSG = "new record succesfully inserted ..."; header("location: attach.php") ; } else { $errMSG = "error while inserting...."; } } } ?> Publishing Books